<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/core/common/top.jsp" %>
<link type="text/css" rel="stylesheet" href="${ctx}/core/styles/validatorAuto.css" />
<script src="${ctx}/core/scripts/formValidator.js" type="text/javascript" charset="UTF-8"></script>
<script src="${ctx}/core/scripts/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<script src="${ctx}/core/scripts/dhtmlXCommon.js" type="text/javascript" charset="UTF-8"></script>
<script src="${ctx}/core/scripts/dhtmlXTree.js" type="text/javascript" charset="UTF-8"></script>
<script language="javascript">
	$(document).ready(function(){
		$.formValidator.initConfig({formid:"form0",onerror:function(msg){showMessage(msg);}});
		$("#roleName").formValidator().inputValidator({min:1,max:60,onerror:"<s:text name='role.name.not.empty'/>",onerrormax:"<s:text name='role.name.over.length'/>"});
		$("#checkedFunc").formValidator().inputValidator({min:1,onerror:"<s:text name='function.not.empty'/>"});
	});	

	var dialogArgment = window.dialogArguments;
	function doOnLoad(){
		preLoadImages();

		tree=new dhtmlXTreeObject(document.getElementById('funcTreebox'),"98%","100%",0);
		tree.setImagePath("${ctx}/core/images/");
		tree.setDragHandler();
		tree.enableCheckBoxes(true);
		tree.enableThreeStateCheckboxes(true);
		//tree.setXMLAutoLoading("${ctx}/systemManage/loadFunc.action");
		//&act=editInput
		var act;
		var systime=new Date().getTime();
		var loadXmlUrl = "${ctx}/systemManage/loadResc.action?systime=" + systime + "&role.id=<s:property value='role.id' />&pageState=${pageState}&loadAll="+dialogArgment;

		loadXmlUrl = encodeURI(loadXmlUrl); 
		loadXmlUrl = encodeURI(loadXmlUrl);
		tree.loadXML(loadXmlUrl);
		tree.enableCheckBoxes(true);
		tree.enableThreeStateCheckboxes(true);
		//tree.openAllItems(0);
	}
	function preLoadImages(){
		var imSrcAr = new Array("line1.gif","line2.gif","line3.gif","line4.gif","minus2.gif","minus3.gif","minus4.gif","plus2.gif","plus3.gif","plus4.gif","icon_1s.gif","books_open.gif","books_close.gif","magazines_open.gif","magazines_close.gif","tombs.gif","tombs_mag.gif","book_titel.gif","iconCheckAll.gif");
		var imAr = new Array(0);
		for(var i=0;i<imSrcAr.length;i++){
			imAr[imAr.length] = new Image();
			imAr[imAr.length-1].src = "${ctx}/core/images/"+imSrcAr[i];
		}
	}
	function getAllLeaf(){ 
		//取得所有选择的选项，并处理
		var allStr=tree.getAllChecked(); 
		var temp=new Array();
		temp=allStr.split(",");
		var str="";
		for(i=0;i<temp.length;i++){
			//alert("open state:"+tree.getOpenState(temp[i]));
			//tree.setUserData(temp[i],"funList",temp[i]+"-user data");
			//alert("is item checked:"+tree.isItemChecked(temp[i]));
			//alert("level:"+tree.getLevel(temp[i]));
			//var state=tree.getOpenState(temp[i]);
			//if(state=='0'){
			//}
			if(i!=temp.length-1){
				str=str+temp[i]+",";
			}else{
				str=str+temp[i];
			}
		}
		//var obj=document.all("funStr");
		obj=document.mainform.checkedFunc;
		obj.value=str;
	}
   	function submitForm(obj){
        var messages_array = new Array();
        getAllLeaf();
       
		return true;
   	} 	
	$(document).ready(function(){
		doOnLoad();
		
	});
	
	function doCancel(){
		location="${ctx}/systemManage/roleSearch.action?act=reQuery";
	}
</script>
<body style="overflow-x:hidden;overflow-y:auto;" >
<form id="form0" method="post" name="mainform" action="${ctx}/systemManage/role.action" onsubmit="return submitForm(this);">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
<%@include file="/WEB-INF/core/common/message.jsp"  %>
  <tr width="100%">
			<td>
				<table border="0" align="center" cellpadding="0" cellspacing="0">
					<tr width="100%">
						<td width="8" height="27" align="left"><img src="${ctx}/core/images/button_05.gif" width="8" height="27" /></td> 
    					<td width="99%"  align="left" background="${ctx}/core/images/button_06.gif" class="bluecu">&nbsp;<img src="${ctx}/core/images/icon_04.gif" />&nbsp;<s:text name="role.roleManage" /></td>
    					<td width="8" align="right"><img src="${ctx}/core/images/button_07.gif" width="8" height="27" /></td>
    				</tr>
    			</table>
    		</td>
  		</tr>
  <tr>
    <td colspan="3" class="biaoge"><table width="100%" border="0" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF">
      <tr align="left">
      <!--角色名称-->
        <td width="6%" height="20" bgcolor="#DDE4EA" nowrap>&nbsp;<s:text name='role.roleName' />&nbsp;<font color="red">*</font></td>
        <td bgcolor="#DDE4EA">
        <s:if test="pageState=='view'">
        	<s:textfield id="roleName" name="role.name" value="%{role.name}" class="textbox_css" style="width:150px" required="true" theme="simple" readonly="true"/>
        </s:if>
        <s:else>
       		<s:textfield id="roleName" name="role.name" value="%{role.name}" class="textbox_css" style="width:150px" required="true" theme="simple"/>
        </s:else>
		</td>
		<!--描述-->
        <td width="6%" bgcolor="#DDE4EA" nowrap>&nbsp;<s:text name='role.remark' />&nbsp;</td>
        <td bgcolor="#DDE4EA">
       	<s:if test="pageState=='view'">
        	<s:textfield name="role.remark" value="%{role.remark}" class="textbox_css" style="width:150px" theme="simple" readonly="true"/>
        </s:if>
        <s:else>
       		<s:textfield name="role.remark" value="%{role.remark}" class="textbox_css" style="width:150px" theme="simple"/>
      	</s:else>
      	</td>
      </tr>
    </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="25" align="left" class="blue">&nbsp;<s:text name='role.includeFunction' />&nbsp;<input type="hidden" id="checkedFunc" name="checkedFunc"  value=""></td>
        </tr>
        <tr height="350" align="left">
          <td><div id="funcTreebox" style="width:100%; height:100%;background-color:#f5f5f5;border :1px solid Silver; overflow-y:auto;overflow-x:none;"></div></td>
        </tr>
        <tr>
          <td height="30" align="center" valign="bottom">
        <s:if test="pageState=='add'">
        	<input name="act" type="hidden" value="addSubmit"/>
        </s:if>
        <s:if test="pageState=='edit'">
        	<input name="role.id" type="hidden" value="<s:property value='role.id' />" />
        	<input name="act" type="hidden" value="editSubmit"/>
        	<input name="pageState" type="hidden" value="edit"/>
        </s:if>
        <!-- input name="role.mgrDmnCode" type="hidden" value="<s:property value='role.mgrDmnCode' />" /-->
        <input name="oldName" type="hidden" value="<s:property value='role.name' />" />
        <s:if test="pageState!='view'">
		  <input id="saveButton" type="submit" class="btn" value="<s:text name='button.save' />" />
		</s:if>
          <input id="returnButton" onclick="doCancel();" type="button" value="<s:text name='button.return'/>" class="btn"/></td>
        </tr></table>
      </td></tr></table>
</form>
	<script language="javascript">
		var oldValue = document.getElementById('roleName').value;
		document.getElementById('roleName').value = oldValue.substring(5,oldValue.length);
		document.getElementById('roleName').focus();
	</script>
</body>